// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file HelloWorldPublisher.h
 *
 */

#ifndef HELLOWORLDPUBLISHER_H_
#define HELLOWORLDPUBLISHER_H_



//#include <fastrtps/fastrtps_fwd.h>
//#include <fastrtps/attributes/PublisherAttributes.h>
//#include <fastrtps/publisher/PublisherListener.h>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/topic/Topic.hpp>

#include <fastrtps/attributes/ParticipantAttributes.h>
#include <fastrtps/Domain.h>

#include "Message.h"

using namespace eprosima::fastdds::dds;
using namespace eprosima::fastrtps::rtps;

class HelloWorldPublisher {
public:
    HelloWorldPublisher();
    virtual ~HelloWorldPublisher();
    //!Initialize
    bool init();
    //!Publish a sample
//    bool publish(bool waitForListener = true);
    //!Run for number samples
//    void run(uint32_t number = 1, uint32_t sleep = 1);

    bool WriterMessage(std::string topic_name, const HelloWorld& message);

private:
//    HelloWorld m_Hello;
//    eprosima::fastrtps::Participant* mp_participant;
//    eprosima::fastrtps::Publisher* mp_publisher;
//    bool stop;
//    class PubListener:public eprosima::fastrtps::PublisherListener
//    {
//    public:
//        PubListener():n_matched(0),firstConnected(false){};
//        ~PubListener(){};
//        void onPublicationMatched(eprosima::fastrtps::Publisher* pub, eprosima::fastrtps::rtps::MatchingInfo& info);
//        int n_matched;
//        bool firstConnected;
//    }m_listener;
//    void runThread(uint32_t number, uint32_t sleep);
//    HelloWorldPubSubType m_type;
private:
    TypeSupport m_sampleType;
    DomainParticipant* m_participant;
    Publisher* m_publisher;

    std::map<std::string
            ,std::pair<Topic*,DataWriter*>> m_Writer;

};



#endif /* HELLOWORLDPUBLISHER_H_ */